package org.gw.ylc.base.service;

import org.gw.ylc.base.model.Department;
import org.gw.ylc.base.repositories.DepartmentRepository;
import org.gw.ylc.base.util.PermissionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {
	@Autowired
	private DepartmentRepository departmentRepository;

	private static DepartmentService INSTANCE;
	
	public DepartmentService() {
		INSTANCE = this;
	}

	public static DepartmentService getINSTANCE() {
		return INSTANCE;
	}
	
	@Cacheable(value = "common.Department",key="#id")
	public Department findById(String id) {
		return departmentRepository.findOne(id);
	}
	
	public Iterable<Department> findAll() {
		return departmentRepository.findByDepartment(PermissionUtil.getFilteredDepartmentId(null));
	}

	public List<Department> findByStatusAndType(Integer status, Integer type) {
		return departmentRepository.findByStatusAndType(PermissionUtil.getFilteredDepartmentId(null), status, type);
	}
}
